
<title>员工 - 工资统计报表 - 报表管理</title>

<div class="row">
	<div class="col-xs-12">

		<div class="widget-box">
			<div class="widget-header">选择计算条件</div>

			<div class="widget-body" style="display: block;">
				<form id="conditionForm">
					<div class="widget-main">
						<div class="row">
							<div class="col-md-2  col-md-push-1">
								<label>年度</label><select id="yearList" class="form-control"></select>
							</div>
							<div class="col-md-2  col-md-push-1">
								<label>月度</label><select id="monthList" class="form-control"></select>
							</div>
							<div class="col-md-2  col-md-push-1">
								<label>部门</label><select id="depList" class="form-control"></select>
							</div>
							<div class="col-md-2  col-md-push-1">
								<label>员工</label><select id="empList" class="form-control"><option
										value="null">请选择</option></select> <br />
							</div>

							<div class="col-md-5  col-md-push-1">
								<label>统计范畴： </label> <input id="comChk" type="checkbox"
									value="com" />公司&nbsp;&nbsp; <input id="depChk"
									type="checkbox" value="dep" />部门&nbsp;&nbsp; <input
									id="empChk" type="checkbox" value="emp" />员工
							</div>

							<div class="col-md-4">
								<input type="submit" value="查询" class="btn btn-primary" />
								<!-- 导出成 Excel 表格; 点击<查询>按钮 取消disabled属性 -->
								<button disabled class="btn btn-primary">导出</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>

		<br />
		<div id="comHeader"></div>
		<div id="depHeader"></div>
		<div id="empHeader"></div>

	</div>
</div>
<script type="text/javascript">
	var scripts = [ null, null ];
	
	$('.page-content-area')
			.ace_ajax(
					'loadScripts',
					scripts,
					function() {
						
						/* 动态加载[部门]列表 */
						$.ajax({
							type : "GET",
							url : "json/department_info.json",
							success : function(data) {
								var options = data;
								$("#depList").empty();
								$("#depList").append(
										"<option value=\"null\">请选择</option>");
								for (var i = 0; i < options.length; i++) {
									var option = options[i];
									$("#depList").append(
											"<option value=\"" + 
											option.dep_id + "\">"
													+ option.dep_name
													+ "</option>");
								}
							}
						});

						/* 动态加载[年度][月度]列表 */
						$("#yearList").append(
								"<option value=\"null\">请选择</option>");
						for (var i = 2010; i < 2020; i++) {
							$("#yearList").append(
									"<option value=\"" + i + "\">" + i
											+ "年</option>");
						}
						$("#monthList").append(
								"<option value=\"null\">请选择</option>");
						for (var i = 1; i < 13; i++) {
							$("#monthList").append(
									"<option value=\"" + i + "\">" + i
											+ "月</option>");
						}

						/* 级联部门选中 加载员工下拉 */
						$("#depList")
								.bind(
										"change",
										function() {
											$
													.ajax({
														type : "GET",
														url : "json/emp_info.json",
														success : function(data) {
															var options = data;
															$("#empList")
																	.empty();
															$("#empList")
																	.append(
																			"<option value=\"null\">请选择</option>");
															for (var i = 0; i < options.length; i++) {
																var option = options[i];
																$("#empList")
																		.append(
																				"<option value=\"" + 
												option.emp_id + "\">"
																						+ option.emp_name
																						+ "</option>");
															}
														}
													});
										});

						/* 查询参数为空的表单验证 和 异步加载结果 */
						$("#conditionForm")
								.bind(
										"submit",
										function() {
											var err = "";

											if ($("#yearList").val() == "null") {
												err += "- 亲，请指定 [年度] 信息 - \n";
											}
											if ($("#monthList").val() == "null") {
												err += "- 亲，请指定 [月度] 信息 - \n";
											}
											if ($("#depChk").attr("checked") == "checked"
													&& $("#depList").val() == "null") {
												err += "- 亲，请指定 [部门] 信息 - \n";
											}
											if ($("#empChk").attr("checked") == "checked"
													&& $("#empList").val() == "null") {
												err += "- 亲，请指定 [员工] 信息 - \n";
											}

											if (err == "") {
												$(
												"#comHeader")
												.empty();
												$(
												"#depHeader")
												.empty();
												$(
												"#empHeader")
												.empty();
												/* 异步加载查询结果 */
												if ($("#comChk")
														.prop("checked")) {
													$
															.ajax({
																type : "GET",
																url : "json/company_statement_fake.json",
																success : function(
																		data) {
																	var trs = data;
																	$(	"#comHeader").append("<label>公司 年度/月度 工资统计报表</label><table id=\"showCom\" class=\"table table-bordered table-hover text-center\"></table>");
																	for (var i = 0; i < trs.length; i++) {
																		var tr = trs[i];
																		/* 生成表头 */
																		if (i == 0) {
																			$(
																					"#showCom")
																					.append(
																							"<thead>"
																									+ "<tr><th>"
																									+ tr.yr_mon
																									+ "</th><th>"
																									+ tr.total_salary
																									+ "</th><th>"
																									+ tr.avg_salary
																									+ "</th><th>"
																									+ tr.min_salary
																									+ "</th><th>"
																									+ tr.max_salary
																									+ "</th>"
																									+ "</thead>");
																		}
																		/* 生成数据 */
																		else {
																			$(
																					"#showCom")
																					.append(
																							"<tbody>"
																									+ "<tr><td>"
																									+ tr.yr_mon
																									+ "</td><td>"
																									+ tr.total_salary
																									+ "</td><td>"
																									+ tr.avg_salary
																									+ "</td><td>"
																									+ tr.min_salary
																									+ "</td><td>"
																									+ tr.max_salary
																									+ "</td>"
																									+ "</tbody>");
																		}
																	}
																}
															});
												}

												if ($("#depChk")
														.prop("checked")) {
													$
															.ajax({
																type : "GET",
																url : "json/department_statement_fake.json",
																success : function(
																		data) {
																	var trs = data;
																	$(	"#depHeader").append("<label>部门 年度/月度 工资统计报表</label><table id=\"showDep\" class=\"table table-bordered table-hover text-center\"></table>");
																	for (var i = 0; i < trs.length; i++) {
																		var tr = trs[i];
																		/* 生成表头 */
																		if (i == 0) {
																			$(
																					"#showDep")
																					.append(
																							"<thead>"
																									+ "<tr><th>"
																									+ tr.dep_id
																									+ "</th><th>"
																									+ tr.dep_name
																									+ "</th><th>"
																									+ tr.yr_mon
																									+ "</th><th>"
																									+ tr.total_base_salary
																									+ "</th><th>"
																									+ tr.avg_base_salary
																									+ "</th><th>"
																									+ tr.min_base_salary
																									+ "</th><th>"
																									+ tr.max_base_salary
																									+ "</th>"
																									+ "</thead>");
																		}
																		/* 生成数据 */
																		else {
																			$(
																					"#showDep")
																					.append(
																							"<tbody>"
																									+ "<tr><td>"
																									+ tr.dep_id
																									+ "</td><td>"
																									+ tr.dep_name
																									+ "</td><td>"
																									+ tr.yr_mon
																									+ "</td><td>"
																									+ tr.total_base_salary
																									+ "</td><td>"
																									+ tr.avg_base_salary
																									+ "</td><td>"
																									+ tr.min_base_salary
																									+ "</td><td>"
																									+ tr.max_base_salary
																									+ "</td>"
																									+ "</tbody>");
																		}
																	}
																}
															});
												}

												if ($("#empChk")
														.prop("checked")) {
													$
															.ajax({
																type : "GET",
																url : "json/employee_statement_fake.json",
																success : function(
																		data) {
																	var trs = data;
																	var tag = "th";
																	$(	"#empHeader").append("<label>员工 年度/月度 工资统计报表</label><table id=\"showEmp\" class=\"table table-bordered table-hover text-center\"></table>");
																	for (var i = 0; i < trs.length; i++) {
																		var tr = trs[i];
																		/* 生成表头 */
																		if (i == 0) {
																			$(
																					"#showEmp")
																					.append(
																							"<thead>"
																									+ "<tr><th>"
																									+ tr.emp_id
																									+ "</th><th>"
																									+ tr.emp_name
																									+ "</th><th>"
																									+ tr.total_base_salary
																									+ "</th><th>"
																									+ tr.total_pension
																									+ "</th><th>"
																									+ tr.total_medical
																									+ "</th><th>"
																									+ tr.total_housing_fund
																									+ "</th><th>"
																									+ tr.total_sickleave_hold
																									+ "</th><th>"
																									+ tr.total_overwork_salary
																									+ "</th>"
																									+ "</thead>");
																		}
																		/* 生成数据 */
																		else {
																			$(
																					"#showEmp")
																					.append(
																							"<tbody>"
																									+ "<tr><td>"
																									+ tr.emp_id
																									+ "</td><td>"
																									+ tr.emp_name
																									+ "</td><td>"
																									+ tr.total_base_salary
																									+ "</td><td>"
																									+ tr.total_pension
																									+ "</td><td>"
																									+ tr.total_medical
																									+ "</td><td>"
																									+ tr.total_housing_fund
																									+ "</td><td>"
																									+ tr.total_sickleave_hold
																									+ "</td><td>"
																									+ tr.total_overwork_salary
																									+ "</td>"
																									+ "</tbody>");
																		}
																	}
																}
															});
												}

												return false;
											} else {
												alert(err);
												return false;
											}
										});

					});
</script>